/**
 * 新增set类型数据
 */
Vue.component("new-set", {
    template :
        `
        <div>
            {{conversion}}
            <Input type="textarea" v-for="(val, index) in values" v-model="val" :autosize="{minRows: 5, maxRows: 10}" placeholder="请输入..." @on-change="returnValue(index, val)"/>
            <Button type="dashed" icon="ios-plus-empty" @click="newLine">
                <span>新增一行...</span>
            </Button>
        </div>
        `
    ,
    props: ["value"],
    data : function () {
        return {
            values : []
        };
    },
    methods : {
        returnValue: function (index, value) {
            this.values[index] = value;
            this.$emit("returnValue", JSON.stringify(this.values));
        },
        newLine : function () {
            this.values.push("");
        }
    },
    computed : {
        conversion : function () {
            var txt = this.value;
            if(txt && txt.indexOf("[") == 0){
                this.values = JSON.parse(txt);
            }else {
                this.values = [txt];
            }
        }
    }
});